package classes.multithread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author : DuJiabao
 * @Date : 2021/2/9 9:56
 * @Project : java_learning
 * @File : null.java
 * @Desc :
 */
public class FixedThreadPoolTest {
  public static void main(String[] args) throws InterruptedException {
    ExecutorService executorService = Executors.newFixedThreadPool(3);
    // 这是任务
    RunnableImpl r1 = new RunnableImpl();
    RunnableImpl r2 = new RunnableImpl();
    RunnableImpl r3 = new RunnableImpl();
    RunnableImpl r4 = new RunnableImpl();
    RunnableImpl r5 = new RunnableImpl();
    // 线程池会根据指定的固定大小，先执行完前面几个任务，再开始执行后面的任务
    executorService.execute(r1);
    executorService.execute(r2);
    executorService.execute(r3);

    executorService.execute(r4);
    executorService.execute(r5);

    executorService.shutdown();
  }
}
